﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using Longbow.Data;
using Gammar.Price.ObjectModel;

namespace Gammar.Price.DataAccess
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Sp_Search : ReaderCommand<Sp_SearchEntity>
    {
        private string _keyWord;
        private int? _pageIndex;
        private int? _pageSize;

        /// <summary>
        /// 
        /// </summary>            
        public Sp_Search(string keyWord, int? pageIndex, int? pageSize)
        {
            _keyWord = keyWord;
            _pageIndex = pageIndex;
            _pageSize = pageSize;
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override CommandType CommandType
        {
            get { return CommandType.StoredProcedure; }
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override string CommandText
        {
            get { return "sp_Search"; }
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override void AddParameters(DbParameterCollection parameters, DBAccess db)
        {
            parameters.Add(db.CreateParameter("@keyWord", DBAccess.ToDBValue(_keyWord), ParameterDirection.Input));
            parameters.Add(db.CreateParameter("@pageIndex", DBAccess.ToDBValue(_pageIndex), ParameterDirection.Input));
            parameters.Add(db.CreateParameter("@pageSize", DBAccess.ToDBValue(_pageSize), ParameterDirection.Input));
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override Sp_SearchEntity ParseRow(DbDataReader reader)
        {
            Sp_SearchEntity obj = new Sp_SearchEntity();
            obj.RowNumber = (long?)DBAccess.ToObjectValue(reader["RowNumber"]);
            obj.Oc_id = (Guid?)DBAccess.ToObjectValue(reader["Oc_id"]);
            obj.Title = (string)DBAccess.ToObjectValue(reader["Title"]);
            obj.CategoryId = (Guid?)DBAccess.ToObjectValue(reader["CategoryId"]);
            obj.CategoryName = (string)DBAccess.ToObjectValue(reader["CategoryName"]);
            obj.Price = (string)DBAccess.ToObjectValue(reader["Price"]);
            obj.PresideUnit = (string)DBAccess.ToObjectValue(reader["PresideUnit"]);
            obj.SrcWeb = (string)DBAccess.ToObjectValue(reader["SrcWeb"]);
            obj.Introduction = (string)DBAccess.ToObjectValue(reader["Introduction"]);
            obj.Url = (string)DBAccess.ToObjectValue(reader["Url"]);
            obj.ItemCount = (int?)DBAccess.ToObjectValue(reader["ItemCount"]);
            obj.Counter = (int?)DBAccess.ToObjectValue(reader["Counter"]);
            return obj;
        }
    }
}